package cn.jiangjiesheng.bootstrap.cloud.service.validator;

import cn.hutool.core.collection.CollUtil;
import cn.jiangjiesheng.bootstrap.cloud.service.ProjectMetadataProperties;
import cn.jiangjiesheng.bootstrap.commons.context.EntContext;
//import cn.jiangjiesheng.bootstrap.qpaas.domain.userorg.mapper.QpaasEnterpriseMapper;
//import cn.jiangjiesheng.bootstrap.qpaas.util.QpaasTableUtils;
import com.google.common.collect.Lists;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 描述：配置文件校验
 *
 * @auth: panyu
 * @createDate: 2023/5/19  14:22
 */
//@Configuration
@Data
@Slf4j
@DependsOn({"qpaasEnterpriseMapper", "qpaasTableUtils", "projectMetadataProperties"})
public class EntIdValidatorConfig {

//    @Autowired
//    private QpaasEnterpriseMapper qpaasEnterpriseMapper;
//
//    @Autowired
//    private QpaasTableUtils qpaasTableUtils;

    @Autowired
    private ProjectMetadataProperties projectMetadataProperties;

    public List<String> validate() {
        log.info("shengxing-commmons.yaml project-metadata.entIdList validating");
        Map<String, List<String>> rtnMap = new HashMap<>();
        List<String> metadataErrorList = new ArrayList<>();
        if (CollUtil.isNotEmpty(projectMetadataProperties.getEntIdList())) {
            EntContext.setEntId(projectMetadataProperties.getEntIdList().get(0));
//            List<String> rightEntIdList = qpaasEnterpriseMapper.getEnterpriseByIds(qpaasTableUtils.getEnterpriseTable(), projectMetadataProperties.getEntIdList());
            List<String> rightEntIdList = Lists.newArrayList("ent_mock");
            metadataErrorList = projectMetadataProperties.getEntIdList().stream().filter(v -> !rightEntIdList.contains(v)).collect(Collectors.toList());
        }
        return metadataErrorList;
    }
}
